package com.controller;

import com.dto.AuthRequest;
import com.dto.AuthResponse;
import com.entity.SystemUser;
import com.service.SystemUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    public SystemUserService userService;

    @PostMapping("/login")
    public AuthResponse login(@RequestBody AuthRequest user) {
        return userService.login(user);
    }

    @GetMapping
    public Page<SystemUser> findAll(@RequestParam(defaultValue = "1") int page,
                                    @RequestParam(defaultValue = "10") int size) {
        return userService.findAll(page - 1, size);
    }

    @PostMapping
    public SystemUser save(@RequestBody SystemUser user) {
        return userService.save(user);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable Integer id) {
        userService.delete(id);
    }
}
